<?php 
use Yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\widgets\LinkPager;
use yii\helpers\Url;
echo $this->render('_centerHeader');?>
<table>
	<?php foreach($articles as $k=>$v){?>
	<tr>
		<td><input type="checkbox" name='items' value='<?php echo $v['article_id']?>'></td>
		<td><a href="">
		<?php if(mb_strlen($v['article_title'])>20){
				echo mb_substr($v['article_title'],0,20,'utf-8').'...';
			}else{
				echo $v['article_title'];
			}
		?></a></td>
		<td><a href="javascript:void(0)" class="darticle" article="<?php echo $v['article_id']?>">删除</a></td>
	</tr>
	<?php }?>
	
</table><?php echo LinkPager::widget([
				'pagination' => $pagination,
				'prevPageLabel'=>'上一页',
				'nextPageLabel'=>'下一页',
			]);?>
<input type="button" id='submit' value='批量删除'>
<script>
	 $("#submit").click(function() {
		 if(confirm("确定要删除收藏吗？"))
	    {
			var isc = "";
			$("input[name=items]").each(function(){ //遍历table里的全部checkbox
				if($(this).prop("checked")) //如果被选中

					isc += $(this).val() + ","; //获取被选中的值
			});
			if(isc.length > 0) //如果获取到
				isc = isc.substring(0, isc.length - 1); //把最后一个逗号去掉
			$.ajax({
			   type: "POST",
			   url: "<?= Url::to(['center/delarticle'])?>",
			   data: "article_id="+isc,
			   success: function(msg){
				 if(msg == 1){
					alert('删除成功')
					location.reload();
				 }
			   }
			});
		}else{
			return false;
		}
    });  
	$(".darticle").click(function(){
		if(confirm("确定要删除此收藏吗？"))
	    {
			var article_id = $(this).attr('article')
			$.ajax({
			   type: "POST",
			   url: "<?= Url::to(['center/delarticle'])?>",
			   data: "article_id="+article_id,
			   success: function(msg){
				 if(msg == 1){
					alert('删除成功')
					location.reload();
				 }
			   }
			});
	    }else{
			return false;
	    }
	})
</script>